package cac.fenjian.resource.AoTask.MsTaskAo.rest;

import cac.fenjian.resource.AoTask.MsTaskAo.dto.MsTaskAoDTO;
import cac.fenjian.resource.AoTask.MsTaskAo.service.MsTaskAoService;
import com.alibaba.fastjson.JSON;
import com.cac.dme.adapter.rest.msg.PageParameter;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Handler;

/**
 * @program test-curd
 * @description AO分拣任务服务接口
 * @author: LSL
 * @create: 2022-08-29-15-29
 **/
@RestController
@RequestMapping("/MsTaskAo")
public class MsTaskAoRest {
    @Autowired
    private MsTaskAoService msTaskAoService;

    /**
     * AO分拣任务数据显示接口
     *
     * @param
     * @return
     */
    @PostMapping("/searchByPage")
    public ResponseMsg<QueryRespBean<HashMap>> searchByPage(@RequestBody HashMap map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
        String msTaskPackageId = (String) map.get("msTaskPackageId");
        String param = JSON.toJSONString(map.get("pageParameter"));
        PageParameter pageParameter = JSON.parseObject(param, PageParameter.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        QueryRespBean<HashMap> result = msTaskAoService.searchByPage(queryReqBean, msTaskPackageId);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 工艺更改AO查询
     *
     * @param
     * @return
     */
    @PostMapping("/searchChangedAo")
    public ResponseMsg<QueryRespBean<HashMap>> searchChangedAo(@RequestBody HashMap map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
        //获取分页参数
        String param = JSON.toJSONString(map.get("pageParameter"));
        //实例化分页对象
        PageParameter pageParameter = JSON.parseObject(param, PageParameter.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        QueryRespBean<HashMap> result = msTaskAoService.searchChangedAo(queryReqBean);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }

    /**
     * 工艺更改ao物料查询
     *
     * @param
     * @return
     */
    @PostMapping("/searchMaterialChanged")
    public ResponseMsg<QueryRespBean<HashMap>> searchMaterialChanged(@RequestBody HashMap map) {
        ResponseMsg<QueryRespBean<HashMap>> responseMsg = new ResponseMsg<>();
        //获取分页参数
        String param = JSON.toJSONString(map.get("pageParameter"));
        String msTaskAoId = (String) map.get("msTaskAoId");
        //实例化分页对象
        PageParameter pageParameter = JSON.parseObject(param, PageParameter.class);
        QueryReqBean<HashMap> queryReqBean = new QueryReqBean<>();
        queryReqBean.setPageParameter(pageParameter);
        QueryRespBean<HashMap> result = msTaskAoService.searchMaterialChanged(queryReqBean, msTaskAoId);
        responseMsg.setResponseBody(result);
        return responseMsg;
    }
}
